// pages/search-result/index.js
const handler = require("../../utils/function.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    spinShow: true,
    visible1: false,
    actions1: [
      {
        name: '预约课程',
      },
      {
        name: '去分享',
        icon: 'share',
        openType: 'share'
      }
    ],
    search_result_list:true,
    scrollTop: false,
    visible2:false,

    tearcher_data:[],
    loading:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initData();
  },

  initData: function (val) {
    var para = {
      content: val,
    };
    var that = this;
    that.setData({
      loading:true
    })
    handler.requestData("search", para, function (res) {
      if (res.success == true) {
         that.setData({
           tearcher_data:res.data,
           search_result_list:false,
           loading: false
         })
      } else {
        wx.showToast({
          title: res.message,
          icon: 'loading'
        })
      }
    });
  },

  // 页面登录
  login_test: function (url) {
    if (wx.getStorageSync("user_phone") === "") {
      this.setData({ visible2: true });
    } else {
      handler.intoPageHandler(url);
    }
  },
  handleCloseCancle: function () {
    this.setData({ visible2: false });
  },
  handleCloseOK: function () {
    this.setData({ visible2: false });
    handler.intoPageHandler('../login/index');
  },
  // 页面跳转
  handler_next_page(e) {
    this.login_test(e.currentTarget.dataset.url);
    // handler.intoPageHandler(e.currentTarget.dataset.url);
  },
  // getFocusHandler input输入框获取焦点事件
  // getFocusHandler: function () {
  //   this.setData({ search_result_list: false });
  // },
  // setFocusHandler input输入框失去焦点事件
  setFocusHandler: function () {
    this.setData({ deleteShow: false });
  },
  getKeyWord: function (e) {
    var value = e.detail.value;
    this.initData(value);
     
  },
  get_data() {
    var that = this;
    var i = 0;
    var time = setInterval(() => {
      if (i < 5) { i++; console.log() }
      else { clearInterval(time); that.setData({ spinShow: false }) }
    }, 1000)
  },
  handleOpen1(e) {
    var user_id = e.currentTarget.dataset.userid;
    this.setData({
      visible1: true,
      tearchid: user_id
    });
  },
  handleCancel1() {
    this.setData({
      visible1: false
    });
  },
  onShareAppMessage() {
   
  },
  handleClickItem1(e) {
    this.login_test("../teacher-detail/index?tearchid=" + this.data.tearchid);
  },
  onChange(event) {
    console.log(event.detail, 'click right menu callback data')
  },
  //页面滚动执行方式
  onPageScroll(event) {
    console.log(event);
    event.scrollTop > 83 && this.setData({ scrollTop: true })
    event.scrollTop < 83 && this.setData({ scrollTop: false })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})